#! /bin/sh
cmd=$1
#called by execfun
command_sed()
{
   #first should check if sedscr exist otherwise it will exec the empty sedscr that will  make the file be empty
   if [ ! -e sedscr ];then
     echo 'script file sedscr not exists'
     exit
   fi
   if test "$1" != sedscr
   then
    #todo here
    sed -f  sedscr $1 > /tmp/$x$$
    mv $1 $1.bak
    cp /tmp/$x$$ $1 
   fi
}
#empty function will trigger syntax error
#delete file which extension name is .bak
command_rmbak()
{
 echo $1 > /tmp/bak
 line=`grep "\.bak" /tmp/bak`  
 if [ -z $line ];then
   echo $1
 else
   rm $1
 fi
}

execfun()
{
 if [ -d $1 ];then
  subfiles=`ls $1`
  for x in $subfiles;do
    execfun $1/$x
  done
 elif [ -f $1 ];then
  command_$cmd $1 #I don't find the method to check if a function has a defination
 fi
}

lists=`ls`
for x in $lists;do
 execfun $x
done
